package leecode

func allPathsSourceTarget(graph [][]int) [][]int {
	var result [][]int
	path := make([]int, 0)
	path = append(path, 0)
	var dfs func(graph [][]int, x int)
	dfs = func(graph [][]int, x int) {
		if len(graph)-1 == x {
			result = append(result, path)
			return
		}
		for i := 0; i < len(graph[x]); i++ {
			path = append(path, graph[x][i]) //遍历到的节点加入到路径之中
			dfs(graph, graph[x][i])
			path = path[:len(path)-1]
		}
	}
	return result
}
